import jxl.*
import org.springframework.web.multipart.MultipartHttpServletRequest
import org.springframework.web.multipart.commons.CommonsMultipartFile
import java.text.SimpleDateFormat
import util.IdGenerator

class UploadController {

    def uploadService
    
    def index = {
        render(view:"upload")
    }

    def save = {
        MultipartHttpServletRequest mpr = (MultipartHttpServletRequest)request;
        CommonsMultipartFile file = (CommonsMultipartFile) mpr.getFile("file");

        // 后台校验是否为excel文件
        if (file.getContentType().toString()!="application/vnd.ms-excel") {
            render(view:"uploadError")
        }
        else
        {
            uploadService.uploadExcel(file)
            redirect(controller:'importProduct',action:'list')
        }
    }
}
